home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / copyin / copyin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-08  |  3.4 KB  |  120 lines

  1. /* Benchmark to test copyin/copyout performance. */
  2. /* $Header: /sprite/src/benchmarks/copyin/RCS/copyin.c,v 1.3 92/06/07 18:10:48 kupfer Exp $ */
  3.  
  4. #include <sprite.h>
  5. #include <option.h>
  6. #include <stdio.h>
  7. #include <spriteTime.h>
  8. #include <status.h>
  9. #include <sys/time.h>
  10. #include <unistd.h>
  11. #include <vmTypes.h>
  12.  
  13. #define BUFFER_SIZE    8192    /* see Vm_Cmd; XXX should go into VM header 
  14.                  * file */ 
  15.  
  16. char *buf;            /* Buffer to copy in from. */
  17.  
  18. int copySize[] = {0, 10, 100, 1024, 4096, 8192}; /* various amounts to copy */
  19. int numSizes = sizeof(copySize) / sizeof(int);
  20.  
  21. int iterations = 10000;        /* number of iterations for each copy size */
  22.  
  23. int spoilCOW = 0;        /* write to the buffer to prevent COW from 
  24.                  * giving optimistic results */
  25. int useMakeAccessible = 0;    /* use Vm_MakeAccessible & bcopy instead of 
  26.                  * copyin/out */ 
  27. int copyout = 0;        /* copy kernel->user instead of vice versa */
  28.  
  29. Option optionArray[] = {
  30.     {OPT_DOC, NULL, NULL,
  31.      "Exercise Sprite's copyin routine by passing various amounts\n\
  32. from a dummy buffer to the kernel and reporting the elapsed time."},
  33.     {OPT_TRUE, "cow", (Address)&spoilCOW,
  34.      "Prevent copy-on-write from improving the numbers"},
  35.     {OPT_INT, "iter", (Address)&iterations,
  36.      "Number of times to copy the buffer for each copy amount"},
  37.     {OPT_TRUE, "ma", (Address)&useMakeAccessible,
  38.      "Use Vm_MakeAccessible instead of Vm_CopyIn"},
  39.     {OPT_TRUE, "out", (Address)©out,
  40.      "Do copyout instead of copyin"},
  41. };
  42. int    numOptions = Opt_Number(optionArray);
  43.  
  44. void WriteToBuffer();
  45.  
  46. main(argc, argv)
  47.     int argc;
  48.     char *argv[];
  49. {
  50.     register int i;
  51.     Time startTime, endTime, totalTime;
  52.     int sizeIndex;
  53.     ReturnStatus status;
  54.     int command;        /* "copyin" versus "make accessible" */
  55.     char *operation;        /* printable name of operation */
  56.  
  57.     (void)Opt_Parse(argc, argv, optionArray, numOptions, 0);
  58.     buf = valloc(BUFFER_SIZE);
  59.     if (buf == NULL) {
  60.     fprintf(stderr, "copyin: no memory.\n");
  61.     exit(1);
  62.     }
  63.     if (useMakeAccessible) {
  64.     if (copyout) {
  65.         operation = "MakeAccessible (out)";
  66.         command = VM_DO_MAKE_ACCESS_OUT;
  67.     } else {
  68.         operation = "MakeAccessible (in)";
  69.         command = VM_DO_MAKE_ACCESS_IN;
  70.     }
  71.     } else {
  72.     if (copyout) {
  73.         operation = "Vm_CopyOut";
  74.         command = VM_DO_COPY_OUT;
  75.     } else {
  76.         operation = "Vm_CopyIn";
  77.         command = VM_DO_COPY_IN;
  78.     }
  79.     }
  80.  
  81.     for (sizeIndex = 0; sizeIndex < numSizes; ++sizeIndex) {
  82.     status = Vm_Cmd(VM_SET_COPY_SIZE, copySize[sizeIndex]);
  83.     if (status != SUCCESS) {
  84.         fprintf(stderr, "Can't set copy size to %d: %s\n",
  85.             copySize[sizeIndex], Stat_GetMsg(status));
  86.         exit(1);
  87.     }
  88.     totalTime = time_ZeroSeconds;
  89.     gettimeofday((struct timeval *)&startTime,0);    
  90.     for (i = 0; i < iterations; i++) {
  91.         status = Vm_Cmd(command, buf);
  92.         if (status != SUCCESS) {
  93.         fprintf(stderr, "Can't copy %d bytes: %s\n",
  94.             copySize[sizeIndex], Stat_GetMsg(status));
  95.         exit(1);
  96.         }
  97.         if (spoilCOW) {
  98.         WriteToBuffer(BUFFER_SIZE, buf);
  99.         }
  100.     }
  101.     gettimeofday((struct timeval *)&endTime,0);
  102.     Time_Subtract(endTime, startTime, &totalTime);
  103.     printf("Using %s: copy %4d bytes %d times: %2d.%03d sec\n",
  104.            operation, copySize[sizeIndex], iterations,
  105.            totalTime.seconds, totalTime.microseconds/1000);
  106.     }
  107. }
  108.  
  109. void
  110. WriteToBuffer(length, buffer)
  111.     int length;            /* bytes in buffer */
  112.     char *buffer;        /* buffer to write to */
  113. {
  114.     char *cPtr;
  115.  
  116.     for (cPtr = buffer; cPtr < buffer + length; cPtr += 1024) {
  117.     *cPtr = 'a';
  118.     }
  119. }
  120.